{if !$isLoadScript}
	<link type="text/css" rel="stylesheet" href="__STATIC__/webuploader/css/webuploader.css">
	<script type="text/javascript" charset="utf-8" src="__STATIC__/webuploader/js/webuploader.js"></script>
{/if}
<div class="controls">
	<div id="uploader_{$id}">{:lang('select picture')}</div><!-- 上传按钮 -->
	<input type="hidden" name="{$name}" value="{$value}" id="file_upload_{$id}"><!-- 隐藏域 -->
	<div id="file_list_{$id}"><!-- 文件列表 -->
		{notempty name="image"}
			<div style="width: 100px; position: relative;">
				<image src="/uploads/picture/{$image.path}" width="100" height="100" />
				<a onclick="remove_file_{$id}(this, {$image.id})" style="position: absolute; top: 5px; right: 5px;"><i class="icon-trash"></i></a>
			</div>
		{/notempty}
	</div>
</div>
<script type="text/javascript">
	var id = "#uploader_{$id}"; // 上传按钮
	var $list_{$id} = $('#file_list_{$id}'); // 文件列表
	var uploader_{$id} = WebUploader.create({
		swf: '__STATIC__/webuploader/js/Uploader.swf',
		server: "{:url('core/File/uploadPicture')}",
		pick: id,
		resize: false
	});

	uploader_{$id}.on('fileQueued', function(file) { // 上传队列
		uploader_{$id}.upload();

		toast.showLoading(); // toast
	});
	uploader_{$id}.on('uploadSuccess', function(file, ret) { // 上传成功 file[name,id]
		if ( ret.status==1 ) {
			toast.success("{:lang('upload success')}"); // toast

			$list_{$id}.html('<div style="width: 100px; position: relative;"><image src="'+ret.data.file.url+'" width="100" height="100" /><a onclick="remove_file_{$id}'+'(this,'+ret.data.file.id+')" style="position: absolute; top: 5px; right: 5px;"><i class="icon-trash"></i></a></div>');
			$('#file_upload_{$id}').val(ret.data.file.id);
		} else { // 上传失败
			toast.error("{:lang('upload fail')}"+ret.info); // toast
		}
	});
	uploader_{$id}.on('uploadError', function(file) { // 上传失败
		toast.error("{:lang('upload fail')}");
	});
	uploader_{$id}.on('uploadComplete', function(file) { // 上传完成
	 	toast.hideLoading(); // toast
	});
	
	function remove_file_{$id}(obj, attachId) {
		$('#file_upload_{$id}').val('');
		$(obj).parent('div').remove();
	}
</script>